package com.qingmi.farmer.ui.order.grain;

import android.content.Context;
import android.content.Intent;

import com.qingmi.farmer.R;
import com.qingmi.farmer.data.ActionsCode;
import com.qingmi.farmer.data.UserData;
import com.qingmi.farmer.data.model.GrainOrder;
import com.qingmi.farmer.data.repository.data.GrainDataRepository;
import com.qingmi.farmer.databinding.ActivityGrainOrderDetailBinding;
import com.wjjun.base.ui.base.BaseActivity;
import com.qingmi.farmer.ui.login.LoginActivity;
import com.wjjun.basemvpvm.data.exception.MyException;
import com.wjjun.basemvpvm.data.observer.DefaultObserver;
import com.wjjun.basemvpvm.data.request.SimpleRequest;

import javax.inject.Inject;


/**
 * 粮食订单详情
 */
public class GrainOrderDetailActivity extends BaseActivity<GrainOrderDetailViewModel, ActivityGrainOrderDetailBinding> {

    public static void start(Context context, String id) {
        Intent intent = new Intent(context, GrainOrderDetailActivity.class);
        intent.putExtra(ActionsCode.DATA_ID, id);
        context.startActivity(intent);
    }

    @Inject
    GrainDataRepository grainDataRepository;

    private String id;

    @Override
    public int getLayoutId() {
        return R.layout.activity_grain_order_detail;
    }

    @Override
    protected GrainOrderDetailViewModel initViewModel() {
        return new GrainOrderDetailViewModel();
    }

    @Override
    protected void initContent() {
        grainDataRepository.bind(this);
        super.initContent();
        viewModel.setTitle(getString(R.string.title_order_detail));
        id = getIntent().getStringExtra(ActionsCode.DATA_ID);
    }

    @Override
    protected void initData() {
        super.initData();

        grainDataRepository.getGrainOrderDetail(new DefaultObserver<GrainOrder>() {

            @Override
            public void onNext(GrainOrder grainOrder) {
                viewModel.bindData(grainOrder);
            }

            @Override
            public void onError(MyException e) {
                showToast(e.getMessage());
                finish();
            }
        }, new SimpleRequest(id));
    }


}
